package com.tjn;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class Exercise02 {
    public static void main(String[] args) {
        String user = "tjn";
        String password = "123456";
        String email = "tjn@559.com";
        try {
            reverse(user, password, email);
            System.out.println("注册成功");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
    public static void reverse(String user, String password, String email){
        if(!(user.length() == 2 || user.length() == 3 ||user.length() == 4)){
            throw new RuntimeException("用户名长度必须是2或3或4");
        }
        if(!(password.length() == 6 && checkPassword(password))){
            throw new RuntimeException("密码长度必须为6位并且必须全部是数字");
        }
        int i = email.indexOf("@");
        int j = email.indexOf(".");
        if(!(i > 0 && j > i)){
            throw new RuntimeException("邮箱格式有误");
        }
    }

    //要求密码内容全是数字的方法
    public static boolean checkPassword(String password){
        char[] ch = password.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            if(ch[i] < '0' || ch[i] > '9')
                return false;
        }
        return true;
    }
}
